package com.molichuxing.gateway.bff.stock.services.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.molichuxing.framework.dto.Paged;
import com.molichuxing.framework.dto.TabDto;
import com.molichuxing.framework.exception.BizException;
import com.molichuxing.framework.utils.DateUtil;
import com.molichuxing.framework.utils.ObjectCastUtil;
import com.molichuxing.gateway.bff.stock.convertor.Convert;
import com.molichuxing.gateway.bff.stock.entity.request.modify.StockCarModifyVo;
import com.molichuxing.gateway.bff.stock.entity.response.EntrepotStorageVo;
import com.molichuxing.gateway.bff.stock.entity.response.FenceBaseVo;
import com.molichuxing.gateway.bff.stock.entity.response.StockCarDetailVo;
import com.molichuxing.gateway.bff.stock.entity.response.StockCarVo;
import com.molichuxing.gateway.bff.stock.entity.response.StockRecordBaseVo;
import com.molichuxing.gateway.bff.stock.services.StockCarBffService;
import com.molichuxing.gateway.property.StockStatusEnum;
import com.molichuxing.gateway.utils.RequestAttrUtil;
import com.molichuxing.services.business.dto.request.modify.StockCarBizModifyDto;
import com.molichuxing.services.business.dto.response.DealerStoreInfoBizDto;
import com.molichuxing.services.business.dto.response.OrderDealerPaymentBizDto;
import com.molichuxing.services.business.dto.response.StockCarBizDto;
import com.molichuxing.services.business.dto.response.StockCarDetailDto;
import com.molichuxing.services.business.dto.response.StockRecordBizDto;
import com.molichuxing.services.business.dto.response.VehicleNameBizDto;
import com.molichuxing.services.business.service.OrderDealerBizService;
import com.molichuxing.services.business.service.StockCarBizService;
import com.molichuxing.services.business.service.StockRecordBizService;
import com.molichuxing.services.business.service.StoreBizService;
import com.molichuxing.services.business.service.VehicleBizService;
import com.molichuxing.services.infrastructure.dto.request.create.FenceExceptionCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.IovFenceBindingCreateDto;
import com.molichuxing.services.infrastructure.dto.request.modify.IovFenceBindingModifyDto;
import com.molichuxing.services.infrastructure.dto.response.CarDto;
import com.molichuxing.services.infrastructure.dto.response.EntrepotStorageDto;
import com.molichuxing.services.infrastructure.dto.response.IovFenceDto;
import com.molichuxing.services.infrastructure.dto.response.StockCarDto;
import com.molichuxing.services.infrastructure.dto.response.StockStoreDto;
import com.molichuxing.services.infrastructure.dto.response.StoreDetailDto;
import com.molichuxing.services.infrastructure.dto.response.VehicleColorDto;
import com.molichuxing.services.infrastructure.service.CarFenceExceptionService;
import com.molichuxing.services.infrastructure.service.CarService;
import com.molichuxing.services.infrastructure.service.EntrepotStorageService;
import com.molichuxing.services.infrastructure.service.FenceStoreStockService;
import com.molichuxing.services.infrastructure.service.IovFenceService;
import com.molichuxing.services.infrastructure.service.StockCarService;
import com.molichuxing.services.infrastructure.service.StockRecordService;
import com.molichuxing.services.infrastructure.service.StockStoreService;
import com.molichuxing.services.infrastructure.service.StoreDetailService;
import com.molichuxing.services.infrastructure.service.StoreService;
import com.molichuxing.services.infrastructure.service.VehicleColorService;
import com.molichuxing.services.property.CarsTypeEnum;
import com.molichuxing.services.property.FenceStoreStockTypeEnum;
import com.molichuxing.services.property.StockCarCarStatusEnum;
import com.molichuxing.services.property.StockCarStatusEnum;
import com.molichuxing.services.property.StockCarStockTypeEnum;
import com.molichuxing.services.property.StockCarTypeEnum;
import com.molichuxing.services.property.StockRecordStatusEnum;
import com.molichuxing.services.property.StockRecordTypeEnum;

/**
 * 
 * @author liyg 
 * 库存车辆bff服务实现类 
 * 2019-09-07
 *
 */
@Service("stockCarBffService")
public class StockCarBffServiceImpl implements StockCarBffService {
	
	 private static final Logger logger = LoggerFactory.getLogger(StockCarBffServiceImpl.class);

	@Resource
	private StockCarBizService stockCarBizService;
	
	@Resource
	private StockCarService stockCarService;
	
	@Resource
	private StockRecordBizService stockRecordBizService;

	@Resource
	private StockStoreService stockStoreService;

	@Resource
	private StoreBizService storeBizService;

	@Resource
	private StoreService storeService;

	@Resource
	private VehicleBizService vehicleBizService;

	@Resource
	private CarService carService;
	
	@Resource
	private VehicleColorService vehicleColorService;
	
	@Resource
	private OrderDealerBizService orderDealerBizService;
	
	@Resource
	private StockRecordService stockRecordService;
	
	@Resource
	private EntrepotStorageService entrepotStorageService;
	
	@Resource
	private IovFenceService iovFenceService;
	
	@Resource
	private StoreDetailService storeDetailService;
	
	@Resource
	private FenceStoreStockService fenceStoreStockService;
	
	@Resource
	private CarFenceExceptionService carFenceExceptionService;

	/**
	 *库存车辆列表
	 * @param map 参数
	 *key:vin            String    车架号 非必填
	 *key:licencePlate   String    车牌号 非必填
	 *key:vehicleId  Integer 车型id 非必填
	 *key:vehicleType  Integer 车辆类型 非必填
	 *key:dealerId   Integer 经销商id 
	 *key:storeId    Integer 门店id 非必填
	 *key:sortName   String 排序字段 
	 *key:sortWay    String 排序方式 
	 *key:pageNum    Integer 当前页
	 *key:pageSize   Integer 每页显示条数
	 * @return
	 * @throws Exception 
	 */
	@Override
	public Paged<StockCarVo> getStockCarList(Map<String, Object> map) throws Exception {
		//获取当前登录的经销商id
        Integer dealerId = RequestAttrUtil.getCurrentDealerId();
        if(null == dealerId){
            throw new BizException("非法入参");
        }
		map.put("dealerId",dealerId);
		String vin = ObjectCastUtil.castString(map.get("vin"));
		String licencePlate = ObjectCastUtil.castString(map.get("licencePlate"));
		Integer vehicleType = ObjectCastUtil.castInteger(map.get("vehicleType"));

		if (StringUtils.isNoneBlank(vin) || StringUtils.isNoneBlank(licencePlate) || null != vehicleType) {
			CarsTypeEnum carsTypeEnum = null;
			if(null != vehicleType) {
				carsTypeEnum = CarsTypeEnum.getEnum(vehicleType);
			}
			List<CarDto> carList= carService.getCarListByCarType(vin, licencePlate, carsTypeEnum);
			if (null == carList || carList.size() <= 0) {
				return new Paged<>();
			}
			
			List<Integer> carIds=new ArrayList<>();
			carList.forEach(dto ->carIds.add(dto.getId()));
			map.put("carIds", carIds);
		}

		List<Integer> storeIds = storeService.getAllStoreIdByDealer(dealerId);
		if (null == storeIds || storeIds.isEmpty()) {
			return new Paged<>();
		}

		List<Integer> stockIds = stockStoreService.getStockIds(storeIds);
		if (null == stockIds || stockIds.isEmpty()) {
			return new Paged<>();
		}
		map.put("stockIds", stockIds);

		Paged<StockCarBizDto> page = stockCarBizService.getDealerStockCarList(map);
		if (null == page) {
			return null;
		} else if (page.isEmpty()) {
			return new Paged<>(null, page.getTotal(), page.getPageSize());
		}

		List<StockCarBizDto> stockCarBizDtoList = page.getList();

		// 获取车辆id集合
		List<Integer> carIds = new ArrayList<>();
		// 获取车型id集合
		List<Integer> vehicleIds = new ArrayList<>();
		// 获取车辆位置门店id集合
		List<Integer> storeStockIds = new ArrayList<>();
		// 获取车辆颜色id集合
		List<Integer> colorIds = new ArrayList<>();

		//获取id
		getId(carIds,vehicleIds,storeStockIds,stockCarBizDtoList);
		
		//获取车辆信息
		Map<Integer, CarDto> carMap= getCarByIds(carIds,colorIds);
		//获取颜色信息
		Map<Integer, VehicleColorDto> vehicleColorMap = vehicleColorService.getVehicleColors(colorIds);
		// 获取车型信息
		Map<Integer, VehicleNameBizDto> vehicleNameMap = vehicleBizService.getCarByModelNameList(vehicleIds);
		// 获取门店经销商信息
		Map<Integer, DealerStoreInfoBizDto> dealerMap = null;
		if (!storeStockIds.isEmpty()) {
			dealerMap = storeBizService.getDealerStoreInfoMap(storeStockIds);
		}

		List<StockCarVo> stockCarVoList = getStockCarVoList(stockCarBizDtoList,carMap,vehicleColorMap,vehicleNameMap,dealerMap);
		Paged<StockCarVo> paged =new Paged<>(stockCarVoList, page.getTotal(), page.getPageSize());
		return paged;
	}

	/**
	 * 获取id
	 * @param carIds
	 * @param vehicleIds
	 * @param storeStockIds
	 * @param colorIds
	 * @param stockCarBizDtoList
	 */
	private void getId(List<Integer> carIds,List<Integer> vehicleIds,List<Integer> storeStockIds,
			List<StockCarBizDto> stockCarBizDtoList) {
		stockCarBizDtoList.forEach(dto ->{
			carIds.add(dto.getCarId());
			vehicleIds.add(dto.getVehicleId());
			Integer stockTypeStore = dto.getStockType();
			if (null != stockTypeStore && StockCarStockTypeEnum.STORE.getValue() == stockTypeStore) {
				storeStockIds.add(dto.getStoreId());
			}
		});
	}
	
	/**
	 *  获取车辆信息
	 * @param carIds
	 * @param colorIds
	 * @return
	 */
	private Map<Integer, CarDto> getCarByIds(List<Integer> carIds,List<Integer> colorIds){
		// 获取车辆信息
		Map<Integer, CarDto> carMap = carService.getCarByIds(carIds);
		if (null == carMap || carMap.isEmpty()) {
			return carMap;
		}
		
		for (Integer key : carMap.keySet()) {
			CarDto carDto = carMap.get(key);
			if (null != carMap) {
				colorIds.add(carDto.getVehicleColorId());
			}
		}
		return carMap;
	}
	
	/**
	 * 封装数据
	 * @param stockCarBizDtoList
	 * @param carMap
	 * @param ownershipMap
	 * @param vehicleNameMap
	 * @param dealerMap
	 * @return
	 */
	private List<StockCarVo> getStockCarVoList(List<StockCarBizDto> stockCarBizDtoList,Map<Integer, CarDto> carMap,Map<Integer, VehicleColorDto> vehicleColorMap,
			Map<Integer, VehicleNameBizDto> vehicleNameMap,Map<Integer, DealerStoreInfoBizDto> dealerMap){
		List<StockCarVo> stockCarVoList=new ArrayList<>();
		stockCarBizDtoList.forEach(dto ->{
			StockCarVo vo = Convert.toStockCarVo(dto);
			
			//获取车辆信息
			CarDto carDto= null == carMap ? null : carMap.get(dto.getCarId());
			vo.setVin(carDto == null ? null : carDto.getVin());
			vo.setLicencePlate(carDto == null ? null : carDto.getLicencePlate());
			vo.setVehicleType(carDto == null ? null : carDto.getVehicleType());
			vo.setVehicleTypeStr(carDto == null ? null : carDto.getVehicleTypeStr());
			
			if(null != carDto) {
				//获取颜色信息
				VehicleColorDto vehicleColorDto= null == vehicleColorMap ? null : vehicleColorMap.get(carDto.getVehicleColorId());
				vo.setColorId(carDto.getVehicleColorId());
				vo.setColorName(vehicleColorDto == null ? null : vehicleColorDto.getName());
			}
			
			//获取车型信息
			VehicleNameBizDto vehicleNameBizDto= null == vehicleNameMap ? null : vehicleNameMap.get(dto.getVehicleId());
			vo.setVehicleName(vehicleNameBizDto== null ? null : 
				vehicleNameBizDto.getSubBrandName()+vehicleNameBizDto.getSeriesName()+vehicleNameBizDto.getModelName());
			
			//获取车辆位置门店信息
			Integer stockType = dto.getStockType();
			Integer storeId = dto.getStoreId();
			if(null != stockType && null != storeId) {
				if(StockCarStockTypeEnum.STORE.getValue() == stockType) {
					DealerStoreInfoBizDto  storeDto = null == dealerMap ? null : dealerMap.get(storeId);
					vo.setStoreId(storeId);
					vo.setStockName(storeDto == null ? null : storeDto.getStoreShortName());
				}
			}
			stockCarVoList.add(vo);
		});
		return stockCarVoList;
	}
	
	/**
	 * 获取库存车辆详情
	 * 
	 * @param carId
	 * @return
	 * @throws Exception 
	 */
	@Override
	public StockCarVo getStockCar(Integer carId) throws Exception {
		StockCarBizDto stockCar = stockCarBizService.getStockCar(carId);
		if(null == stockCar) {
			return null;
		}
		
		StockCarVo vo = Convert.toStockCarVo(stockCar);
		Integer storeId = stockCar.getStoreId();
		if(null != storeId) {
			DealerStoreInfoBizDto dealer= storeBizService.getDealerStoreInfo(storeId);
			if(null != dealer) {
				vo.setStockName(dealer.getDealerShortName()+"-"+dealer.getStoreShortName());
			}
		}
		return vo;
	}
	
	/**
	 * 车辆调拨
	 * @param modifyVo
	 * @return
	 * @throws Exception
	 */
	@Override
	public Boolean modifyAllot(StockCarModifyVo modifyVo) throws Exception {
		
		validateParams(modifyVo);
		Assert.notNull(modifyVo.getStoreId(),"参数storeId不能为空");
		
		StockCarDto stockCarDto = getStockCarDto(modifyVo.getCarId());
		
		StockCarBizModifyDto modifyDto=new StockCarBizModifyDto();
		BeanUtils.copyProperties(modifyVo, modifyDto);
		modifyDto.setStatus(StockCarStatusEnum.YET_STOCK.getValue());
		modifyDto.setStorageTime(DateUtil.convertDateToLDT(new Date()));
		modifyDto.setAccountId(modifyVo.getOperateId());
		modifyDto.setAccountAccount(modifyVo.getOperateName());
		//根据门店id 查询仓库id
		StockStoreDto stockStore = stockStoreService.getStockStoreByStoreId(modifyVo.getStoreId());
		if(null == stockStore ) {
			throw new BizException("门店信息没有仓库信息");
		}
		if(stockStore.getStockId().equals(stockCarDto.getInStockId())) {
			throw new BizException("车辆位置没有发生变化");
		}
		CarDto carDto = getCarDto(modifyVo.getCarId());
		
		//验证围栏
		getModifyBindingFenceVerify(carDto,stockCarDto,"车辆未绑定门店下的围栏");
		//解除门店围栏 
		modifyBindingFence(stockCarDto.getFenceId(),carDto.getVin());
		//围栏验证
		getBindingFenceVerify(carDto, stockCarDto, modifyVo, "车辆已经绑定其它围栏");
		//绑定门店围栏
		createBindingFence(modifyVo.getFenceId(),carDto.getVin());
		modifyDto.setStockId(stockStore.getStockId());
		modifyDto.setStockType(StockCarStockTypeEnum.STORE.getValue());
		//修改车辆所在位置
		modifyStockIdById(modifyVo.getCarId(),modifyDto.getStockId(),StockCarStockTypeEnum.STORE.getValue());
		
		return stockCarBizService.modifyAllotStock(modifyDto);
	}
	
	/**
	 * 获取车辆信息
	 * @param carId
	 * @return
	 */
    private CarDto getCarDto(Integer carId) {
    	CarDto carDto = carService.getCarById(carId);
		if(null == carDto) {
			throw new BizException("不存在该车辆信息");
		}
		return carDto;
    }
	
	
	/**
	 * 围栏绑定
	 * @param fenceId
	 * @param vin
	 * @return
	 */
	private Boolean createBindingFence(Integer fenceId,String vin) {
		IovFenceBindingCreateDto dto = new IovFenceBindingCreateDto();
		if(null == fenceId || StringUtils.isAllBlank(vin)) {
			return false;
		}
		dto.setFenceId(Long.valueOf(fenceId));
		List<String> list= new ArrayList<>(1);
		list.add(vin);
		dto.setListVin(list);
		try {
			return iovFenceService.addBindingFence(dto);
		}catch (Exception e) {
			logger.error("围栏绑定异常：",e);
			return false;
		}
	}
	
	/**
	 * 解绑围栏
	 * @param fenceId
	 * @param vin
	 * @return
	 */
	private Boolean modifyBindingFence(Integer fenceId,String vin) {
		IovFenceBindingModifyDto  dto = new IovFenceBindingModifyDto();
		if(null == fenceId || StringUtils.isAllBlank(vin)) {
			return false;
		}
		dto.setFenceId(Long.valueOf(fenceId));
		List<String> list= new ArrayList<>(1);
		list.add(vin);
		dto.setListVin(list);
		try {
			return iovFenceService.modifyBindingFence(dto);
		}catch (Exception e) {
			logger.error("解绑围栏异常：",e);
			return false;
		}
	}
	
	
	/**
	 * 解除门店围栏 
	 * @param stockId
	 * @param vin
	 */
	private void modifyFenceStore(Integer stockId,String vin){
		StockStoreDto stockStore = getStockStore(stockId);
		StoreDetailDto store = getStoreDetailById(stockStore.getStoreId());
		Boolean flag = modifyBindingFence(store.getFenceId(), vin);
		if(!flag) {
			throw new BizException("车联网解除门店围栏失败!");
		}
	}
	
	/**
	 * 车辆绑定门店围栏
	 * @param storeId
	 * @param vin
	 */
	private void createFenceStore(Integer storeId,String vin) {
		StoreDetailDto store = getStoreDetailById(storeId);
		Boolean flag = createBindingFence(store.getFenceId(),vin);
		if(!flag) {
			throw new BizException("车联网车辆绑定门店围栏失败!");
		}
	}
	
	/**
	 * 根据仓库id 查询门店id 
	 * @param stockId
	 * @return
	 */
	private StockStoreDto getStockStore(Integer stockId) {
		//根据仓库id 查询门店id
		StockStoreDto stockStore = stockStoreService.getStockStore(stockId);
		if(null == stockStore ) {
			throw new BizException("该仓库没有门店信息");
		}
		return stockStore;
	}
	
	/**
	 * 根据门店id获取门店信息
	 * @param storeId
	 * @return
	 */
	private StoreDetailDto getStoreDetailById(Integer storeId) {
		try {
			StoreDetailDto store = storeDetailService.getStoreDetailById(storeId);
			if(null == store) {
				throw new BizException("不存在该门店信息");
			}
			return store;
		} catch (Exception e) {
			logger.error("根据门店id获取门店信息异常：",e);
			throw new BizException("门店服务异常");
		}
	}
	
	/**
	 * 修改车辆所在位置
	 * @param carId
	 * @param stockId
	 * @param stockType
	 */
	private void modifyStockIdById(Integer carId, Integer stockId,  Integer stockType) {
		int num = carService.modifyStockIdById(carId,stockId,stockType);
		if(num != 1) {
		   throw new BizException(102, "车辆入库异常");
		}
	}
	
	/**
	 * 根据车辆id获取库存信息
	 * @param carId
	 * @return
	 */
	private StockCarDto getStockCarDto(Integer carId) {
		StockCarDto stockCarDto = stockCarService.getStockCar(carId);
		if(null == stockCarDto) {
			throw new BizException(101, "不存在该条信息");
		}
		return stockCarDto;
	}
	
	/**
	 * 验证参数
	 * @param modifyVo
	 */
	private void validateParams(StockCarModifyVo modifyVo) {
		Assert.notNull(modifyVo,"参数不能为空");
		Assert.notNull(modifyVo.getCarId(), "carId不能为空");
		Assert.notNull(modifyVo.getFenceId(), "fenceId不能为空");
	}
	
	/**
	 * 还车
	 * @param modifyVo
	 * @return
	 * @throws Exception
	 */
	@Override
	public Boolean modifyReturn(StockCarModifyVo modifyVo) throws Exception {
		validateParams(modifyVo);
		Assert.notNull(modifyVo.getStockId(),"参数stockId不能为空");
		
		StockCarDto stockCarDto = stockCarService.getStockCar(modifyVo.getCarId());
		if(null == stockCarDto) {
			throw new BizException("不存在该条信息");
		}
		
		if(StockCarCarStatusEnum.FOR_RENT.getValue() != stockCarDto.getCarStatus()) {
			throw new BizException("该车辆不是待出租状态不能进行还车");
		}
		
		CarDto carDto = getCarDto(modifyVo.getCarId());
		//验证围栏
		getModifyBindingFenceVerify(carDto,stockCarDto,"车辆未绑定门店下的围栏");
		//解除门店围栏 
		modifyBindingFence(stockCarDto.getFenceId(),carDto.getVin());
		
		StockCarBizModifyDto modifyDto=new StockCarBizModifyDto();
		BeanUtils.copyProperties(modifyVo, modifyDto);
		modifyDto.setStatus(StockCarStatusEnum.WAIT_STOCK.getValue());
		modifyDto.setType(StockCarTypeEnum.COLLECT.getValue());
		modifyDto.setStockType(StockCarStockTypeEnum.ENTREPOT_STORAGE.getValue());
		modifyDto.setStorageTime(DateUtil.convertDateToLDT(new Date()));
		modifyDto.setAccountId(modifyVo.getOperateId());
		modifyDto.setAccountAccount(modifyVo.getOperateName());
		
		return stockCarBizService.modifyOutStock(modifyDto);
	}
	
	/**
	 *到期还车列表
	 * @param map 参数
	 *key:tabType       Integer    tab类型
	 *key:vin            String    车架号 非必填
	 *key:licencePlate   String    车牌号 非必填
	 *key:dealerId   Integer 经销商id 
	 *key:sortName   String 排序字段 
	 *key:sortWay    String 排序方式 
	 *key:pageNum    Integer 当前页
	 *key:pageSize   Integer 每页显示条数
	 * @return
	 * @throws Exception 
	 */
	@Override
	public Paged<StockCarDetailVo> getReturnList(Map<String, Object> map) throws Exception {
		//获取当前登录的经销商id
        Integer dealerId = RequestAttrUtil.getCurrentDealerId();
        if(null == dealerId){
            throw new BizException("非法入参");
        }
		map.put("dealerId",dealerId);
		Integer tabType = ObjectCastUtil.castInteger(map.get("tabType"));
		String vin = ObjectCastUtil.castString(map.get("vin"));
		String licencePlate = ObjectCastUtil.castString(map.get("licencePlate"));
		/*查询门店ids*/
		List<Integer> storeIds = storeService.getAllStoreIdByDealer(dealerId);
		if (null == storeIds || storeIds.isEmpty()) {
			return new Paged<>();
		}
		/*查询仓库ids*/
		List<Integer> stockIds = stockStoreService.getStockIds(storeIds);
		if (null == stockIds || stockIds.isEmpty()) {
			return new Paged<>();
		}
		
		/*获取车辆信息*/
		Map<Integer, OrderDealerPaymentBizDto> orderDealerMap = orderDealerBizService.getOrderDealerPayment(dealerId, null);
		
		//封装tab
	    Paged<StockCarDetailVo> paged=new Paged<>();
	    paged=getEncapsulationTab(paged,dealerId,stockIds,orderDealerMap);

		if (StringUtils.isNoneBlank(vin) || StringUtils.isNoneBlank(licencePlate)) {
			CarDto carDto = carService.getByVinLicencePlate(vin, licencePlate);
			if (null == carDto ) {
				return paged;
			}
			orderDealerMap = orderDealerBizService.getOrderDealerPayment(dealerId, carDto.getId());
		}
		if(null == orderDealerMap || orderDealerMap.isEmpty()) {
			return paged;
		}
		/*获取车辆ids*/
		List<Integer> carIds=new ArrayList<>();
		orderDealerMap.keySet().forEach(key -> carIds.add(key));
		map.put("carIds", carIds);
		
		//获取参数
		getParams(map,tabType);
		//获取分页数据
		paged=getPaged(paged,map,tabType,orderDealerMap);
		
		return paged;
	}
	
	/**
	 * 获取到期还车列表（已回库） 获取分页数据
	 * @param paged
	 * @param map
	 * @param tabType
	 * @return
	 * @throws Exception 
	 */
	private Paged<StockCarDetailVo> getPaged(Paged<StockCarDetailVo> paged, Map<String, Object> map,Integer tabType) throws Exception {
		
		Paged<StockRecordBizDto> returnStockCarPaged= stockRecordBizService.getReturnStockCarList(map);
		if(null == returnStockCarPaged) {
			return paged;
		}else if (returnStockCarPaged.isEmpty()) {
			paged.setPageSize(returnStockCarPaged.getPageSize());
			paged.setTotal(returnStockCarPaged.getTotal());
			return paged;
		}
		
		List<StockRecordBizDto> list = returnStockCarPaged.getList();
		
		// 获取车辆id集合
		List<Integer> carIds = new ArrayList<>();
		// 获取车型id集合
		List<Integer> vehicleIds = new ArrayList<>();
		// 获取车辆发车位置门店id集合
		List<Integer> outStoreStockIds = new ArrayList<>();
		
		list.forEach(dto -> {
			carIds.add(dto.getCarId());
			vehicleIds.add(dto.getVehicleId());
			Integer outStockType = dto.getOutStockType();
			if(outStockType != null && StockCarStockTypeEnum.STORE.getValue() == outStockType) {
				outStoreStockIds.add(dto.getOutStoreId());
			}
		});
		
		//获取车辆信息
		Map<Integer, CarDto> carMap = carService.getCarByIds(carIds);
		//获取车型信息
		Map<Integer, VehicleNameBizDto> vehicleNameMap = vehicleBizService.getCarByModelNameList(vehicleIds);
		//获取门店经销商信息
		Map<Integer, DealerStoreInfoBizDto> outDealerMap = null;
		if (!outStoreStockIds.isEmpty()) {
			outDealerMap = storeBizService.getDealerStoreInfoMap(outStoreStockIds);
		}

		List<StockCarDetailVo> stockCarDetailVoList = getStockCarDetailVoList(list,carMap,vehicleNameMap,outDealerMap);
		paged.setPageSize(returnStockCarPaged.getPageSize());
		paged.setTotal(returnStockCarPaged.getTotal());
		paged.setList(stockCarDetailVoList);
		return paged;
	}

	/**
	 * 获取到期还车列表（待还车 或  回库中） 获取分页数据
	 * @param paged
	 * @param map
	 * @param tabType
	 * @param orderDealerMap
	 * @return
	 * @throws Exception
	 */
	private Paged<StockCarDetailVo> getPaged(Paged<StockCarDetailVo> paged, Map<String, Object> map,Integer tabType,Map<Integer, OrderDealerPaymentBizDto> orderDealerMap) throws Exception {
		
		Paged<StockCarDetailDto> stockCarPaged = stockCarBizService.getReturnStockCarList(map);
		if(null == stockCarPaged) {
			return paged;
		}else if (stockCarPaged.isEmpty()) {
			paged.setPageSize(stockCarPaged.getPageSize());
			paged.setTotal(stockCarPaged.getTotal());
			return paged;
		}
		
		List<StockCarDetailDto> list = stockCarPaged.getList();
		
		// 获取车辆id集合
		List<Integer> carIds = new ArrayList<>();
		// 获取车型id集合
		List<Integer> vehicleIds = new ArrayList<>();
		// 获取车辆发车位置门店id集合
		List<Integer> outStoreStockIds = new ArrayList<>();
		// 获取车辆收车位置门店id集合
		List<Integer> inStoreStockIds = new ArrayList<>();
		
		list.forEach(dto -> {
			carIds.add(dto.getCarId());
			vehicleIds.add(dto.getVehicleId());
			Integer outStockType = dto.getOutStockType();
			if(outStockType != null && StockCarStockTypeEnum.STORE.getValue() == outStockType) {
				outStoreStockIds.add(dto.getOutStoreId());
			}
			Integer inStockType = dto.getInStockType();
			if(inStockType != null && StockCarStockTypeEnum.STORE.getValue() == inStockType) {
				inStoreStockIds.add(dto.getInStoreId());
			}
		});
		
		//获取车辆信息
		Map<Integer, CarDto> carMap = carService.getCarByIds(carIds);
		//获取车型信息
		Map<Integer, VehicleNameBizDto> vehicleNameMap = vehicleBizService.getCarByModelNameList(vehicleIds);
		//获取门店经销商信息
		Map<Integer, DealerStoreInfoBizDto> outDealerMap = null;
		if (!outStoreStockIds.isEmpty()) {
			outDealerMap = storeBizService.getDealerStoreInfoMap(outStoreStockIds);
		}
		//获取门店经销商信息
		Map<Integer, DealerStoreInfoBizDto> inDealerMap = null;
		if (!inStoreStockIds.isEmpty()) {
			inDealerMap = storeBizService.getDealerStoreInfoMap(inStoreStockIds);
		}

		List<StockCarDetailVo> stockCarDetailVoList = getStockCarDetailVoList(list,carMap,vehicleNameMap,orderDealerMap,outDealerMap,inDealerMap);
		paged.setPageSize(stockCarPaged.getPageSize());
		paged.setTotal(stockCarPaged.getTotal());
		paged.setList(stockCarDetailVoList);
		return paged;
	}

	
	/**
	 * 封装数据
	 * @param list
	 * @param carMap
	 * @param vehicleNameMap
	 * @param orderDealerMap
	 * @param outDealerMap
	 * @param inDealerMap
	 * @return
	 */
	private List<StockCarDetailVo> getStockCarDetailVoList(List<StockCarDetailDto> list,Map<Integer, CarDto> carMap,Map<Integer, VehicleNameBizDto> vehicleNameMap
			,Map<Integer, OrderDealerPaymentBizDto> orderDealerMap,Map<Integer, DealerStoreInfoBizDto> outDealerMap,Map<Integer, DealerStoreInfoBizDto> inDealerMap){
		List<StockCarDetailVo> stockCarDetailVoList=new ArrayList<>();
		
		list.forEach(dto -> {

			 StockCarDetailVo vo = Convert.toStockCarDetailVo(dto);
			//获取车辆信息
			CarDto carDto= null == carMap ? null : carMap.get(dto.getCarId());
			vo.setVin(carDto == null ? null : carDto.getVin());
			vo.setLicencePlate(carDto == null ? null : carDto.getLicencePlate());
			
			//获取车型信息
			VehicleNameBizDto vehicleNameBizDto= null == vehicleNameMap ? null : vehicleNameMap.get(dto.getVehicleId());
			vo.setVehicleName(vehicleNameBizDto== null ? null : 
				vehicleNameBizDto.getSubBrandName()+vehicleNameBizDto.getSeriesName()+vehicleNameBizDto.getModelName());
			
			//获取采购单号
			OrderDealerPaymentBizDto  paymentBizDto = null == orderDealerMap ? null : orderDealerMap.get(dto.getCarId());
			vo.setOrderCode(paymentBizDto == null ? null : paymentBizDto.getOrderCode());
			vo.setStockId(paymentBizDto == null ? null : paymentBizDto.getOutStockId());
			
			//获取发车方门店信息
			Integer outStockType = dto.getOutStockType();
			if(null != outStockType) {
				if(StockCarStockTypeEnum.STORE.getValue() == outStockType) {
					DealerStoreInfoBizDto  storeDtoOut = null == outDealerMap ? null : outDealerMap.get(dto.getOutStoreId());
					vo.setOutStockName(storeDtoOut == null ? null : storeDtoOut.getStoreShortName());
				}
			}
			
			//获取收车方门店信息
			Integer inStockType = dto.getInStockType();
			if(null != inStockType) {
				if(StockCarStockTypeEnum.STORE.getValue() == dto.getInStockType()) {
					DealerStoreInfoBizDto  storeDtoIn = null == inDealerMap ? null : inDealerMap.get(dto.getInStoreId());
					vo.setInStockName(storeDtoIn == null ? null : storeDtoIn.getStoreShortName());
				}
			}
			
			stockCarDetailVoList.add(vo);
		});
		return stockCarDetailVoList;
	}
	
	/**
	 * 封装数据
	 * @param list
	 * @param carMap
	 * @param vehicleNameMap
	 * @param outDealerMap
	 * @return
	 */
	private List<StockCarDetailVo> getStockCarDetailVoList(List<StockRecordBizDto> list,Map<Integer, CarDto> carMap,Map<Integer, VehicleNameBizDto> vehicleNameMap
			,Map<Integer, DealerStoreInfoBizDto> outDealerMap){
		List<StockCarDetailVo> stockCarDetailVoList=new ArrayList<>();
		
		list.forEach(dto -> {

			 StockCarDetailVo vo = Convert.toStockCarDetailVo(dto);
			//获取车辆信息
			CarDto carDto= null == carMap ? null : carMap.get(dto.getCarId());
			vo.setVin(carDto == null ? null : carDto.getVin());
			vo.setLicencePlate(carDto == null ? null : carDto.getLicencePlate());
			
			//获取车型信息
			VehicleNameBizDto vehicleNameBizDto= null == vehicleNameMap ? null : vehicleNameMap.get(dto.getVehicleId());
			vo.setVehicleName(vehicleNameBizDto== null ? null : 
				vehicleNameBizDto.getSubBrandName()+vehicleNameBizDto.getSeriesName()+vehicleNameBizDto.getModelName());
			
			//获取发车方门店信息
			Integer outStockType = dto.getOutStockType();
			if(null != outStockType) {
				if(StockCarStockTypeEnum.STORE.getValue() == outStockType) {
					DealerStoreInfoBizDto  storeDtoOut = null == outDealerMap ? null : outDealerMap.get(dto.getOutStoreId());
					vo.setOutStockName(storeDtoOut == null ? null : storeDtoOut.getStoreShortName());
				}
			}
			
			stockCarDetailVoList.add(vo);
		});
		return stockCarDetailVoList;
	}
	
	/**
	 * 获取参数信息
	 * @param map
	 * @param tabType
	 */
	private void getParams(Map<String, Object> map,Integer tabType) {
		
		String sortName = ObjectCastUtil.castString(map.get("sortName"));
		if(null == tabType) {
			map.put("status", StockCarStatusEnum.YET_STOCK.getValue());
			map.put("inStockType", StockCarStockTypeEnum.STORE.getValue());
			getSortParams(map,sortName);
			return;
		}
		
		if(StockStatusEnum.WAIT_RETURN_CAR.getValue() == tabType) {
			map.put("status", StockCarStatusEnum.YET_STOCK.getValue());
			map.put("inStockType", StockCarStockTypeEnum.STORE.getValue());
			getSortParams(map,sortName);
			
		}else if(StockStatusEnum.WAIT_STOCK.getValue() == tabType) {
			map.put("type", StockCarTypeEnum.COLLECT.getValue());
			map.put("status", StockCarStatusEnum.WAIT_STOCK.getValue());
			map.put("inStockType", StockCarStockTypeEnum.ENTREPOT_STORAGE.getValue());
			getSortParams(map,sortName);
			
		}else if(StockStatusEnum.YET_STOCK.getValue() == tabType) {
			map.put("type", StockRecordTypeEnum.COLLECT_IN_STOCK.getValue());
			map.put("status", StockRecordStatusEnum.IN_STOCK.getValue());
			
		}else {
			map.put("status", StockCarStatusEnum.YET_STOCK.getValue());
			map.put("inStockType", StockCarStockTypeEnum.STORE.getValue());
			getSortParams(map,sortName);
		}
	}
	
	/**
	 * 获取默认排序
	 * @param map
	 * @param sortName
	 */
	private void getSortParams(Map<String, Object> map,String  sortName) {
		if(StringUtils.isBlank(sortName)) {
			map.put("sortName", "operationTime");
			map.put("sortWay", "asc");
		}
	}
	
	/**
	 * 获取tab
	 * @param paged
	 * @param dealerId
	 * @param stockIds
	 * @return
	 * @throws Exception
	 */
	private Paged<StockCarDetailVo> getEncapsulationTab(Paged<StockCarDetailVo> paged,Integer dealerId,List<Integer> stockIds,Map<Integer, OrderDealerPaymentBizDto> orderDealerMap) throws Exception {
		
		/*获取车辆ids*/
		List<Integer> carIds=new ArrayList<>();
		if(null != orderDealerMap && !orderDealerMap.isEmpty()) {
			orderDealerMap.keySet().forEach(key -> carIds.add(key));
		}
		
		List<TabDto> tab =new ArrayList<>();
		StockStatusEnum[] values = StockStatusEnum.values();
		for (StockStatusEnum stockStatusEnum : values) {
			TabDto tabDto=new TabDto();
			tabDto.setType(stockStatusEnum.getValue());
			tabDto.setName(stockStatusEnum.getName());
			Long count=0L;
			if(carIds.size()>0) {
				if(StockStatusEnum.WAIT_RETURN_CAR.getValue() == stockStatusEnum.getValue()) {
					count = stockCarService.getCount(StockCarStatusEnum.YET_STOCK.getValue(),StockCarStockTypeEnum.STORE.getValue(),carIds,null);
				}else if(StockStatusEnum.WAIT_STOCK.getValue() == stockStatusEnum.getValue()) {
					count = stockCarService.getCount(StockCarStatusEnum.WAIT_STOCK.getValue(),
							StockCarStockTypeEnum.ENTREPOT_STORAGE.getValue(),carIds,StockCarTypeEnum.COLLECT.getValue());
				}else if(StockStatusEnum.YET_STOCK.getValue() == stockStatusEnum.getValue()) {
					count = stockRecordService.getCount(stockIds);
				}
			}else {
				if(StockStatusEnum.YET_STOCK.getValue() == stockStatusEnum.getValue()) {
					count = stockRecordService.getCount(stockIds);
				}
			}
			tabDto.setCount(count.intValue());
			tab.add(tabDto);
		}
		paged.setTab(tab);
        return paged;
	}
	
	/**
	 *到期还车列表（已回库）
	 * @param map 参数
	 *key:tabType       Integer    tab类型
	 *key:vin            String    车架号 非必填
	 *key:licencePlate   String    车牌号 非必填
	 *key:dealerId   Integer 经销商id 
	 *key:sortName   String 排序字段 
	 *key:sortWay    String 排序方式 
	 *key:pageNum    Integer 当前页
	 *key:pageSize   Integer 每页显示条数
	 * @return
	 * @throws Exception 
	 */
	@Override
	public Paged<StockCarDetailVo> getReturnRecordList(Map<String, Object> map) throws Exception {
		//获取当前登录的经销商id
        Integer dealerId = RequestAttrUtil.getCurrentDealerId();
        if(null == dealerId){
            throw new BizException("非法入参");
        }
		map.put("dealerId",dealerId);
		Integer tabType = ObjectCastUtil.castInteger(map.get("tabType"));
		String vin = ObjectCastUtil.castString(map.get("vin"));
		String licencePlate = ObjectCastUtil.castString(map.get("licencePlate"));
		/*查询门店ids*/
		List<Integer> storeIds = storeService.getAllStoreIdByDealer(dealerId);
		if (null == storeIds || storeIds.isEmpty()) {
			return new Paged<>();
		}
		/*查询仓库ids*/
		List<Integer> stockIds = stockStoreService.getStockIds(storeIds);
		if (null == stockIds || stockIds.isEmpty()) {
			return new Paged<>();
		}
		map.put("stockIds", stockIds);
		
		/*获取车辆信息*/
		Map<Integer, OrderDealerPaymentBizDto> orderDealerMap = orderDealerBizService.getOrderDealerPayment(dealerId, null);
		
		//封装tab
	    Paged<StockCarDetailVo> paged=new Paged<>();
	    paged=getEncapsulationTab(paged,dealerId,stockIds,orderDealerMap);

		if (StringUtils.isNoneBlank(vin) || StringUtils.isNoneBlank(licencePlate)) {
			CarDto carDto = carService.getByVinLicencePlate(vin, licencePlate);
			if (null == carDto ) {
				return paged;
			}
			map.put("carId", carDto.getId());
		}
		
		//获取分页数据
		paged=getPaged(paged,map,tabType);
		
		return paged;
	}
	
	/**
	 * 获取中转库列表
	 * 
	 * @return
	 */
	@Override
	public List<EntrepotStorageVo> getEntrepotStorageList() {
		
		List<EntrepotStorageDto> entrepotStorageList = entrepotStorageService.getEntrepotStorageList();
		List<EntrepotStorageVo> entrepotStorageVoList= Convert.toEntrepotStorageVoBase(entrepotStorageList);
		
		return entrepotStorageVoList;
	}
	
	@Override
	public List<StockRecordBaseVo> getListByCarId(Integer carId) {
		//获取当前登录的经销商id
        Integer dealerId = RequestAttrUtil.getCurrentDealerId();
        if(null == dealerId){
            throw new BizException("非法入参");
        }
		/*查询门店ids*/
		List<Integer> storeIds = storeService.getAllStoreIdByDealer(dealerId);
		if (null == storeIds || storeIds.isEmpty()) {
			throw new BizException("非法入参");
		}
		
		List<StockRecordBizDto> list = stockRecordBizService.getListByCarId(carId, storeIds);
		if(null == list || list.isEmpty()) {
			return null;
		}
		
		//获取发车方门店id集合
		List<Integer> storeIdOuts=new ArrayList<>();
		//获取收车方门店id集合
		List<Integer> storeIdIns=new ArrayList<>();
		
		for (StockRecordBizDto dto : list) {
			
			Integer outStockType = dto.getOutStockType();
			if(null != outStockType) {
				if(StockCarStockTypeEnum.STORE.getValue() == outStockType) {
					storeIdOuts.add(dto.getOutStoreId());
				}
			}
			
			Integer inStockType = dto.getInStockType();
			if(null != inStockType) {
				if(StockCarStockTypeEnum.STORE.getValue() == inStockType) {
					storeIdIns.add(dto.getInStoreId());
				}
			}
		}

		//获取发车方门店信息
		Map<Integer, DealerStoreInfoBizDto> dealerOutMap =null;
		if(!storeIdOuts.isEmpty()) {
			try {
				dealerOutMap= storeBizService.getDealerStoreInfoMap(storeIdOuts);
			} catch (Exception e) {
			   logger.error("获取门店信息异常",e);
			   throw new BizException(500, "获取门店信息异常");
			}
		}
		
		//获取发车方门店信息
		Map<Integer, DealerStoreInfoBizDto> dealerInMap =null;
		if(!storeIdIns.isEmpty()) {
			try {
				dealerInMap=storeBizService.getDealerStoreInfoMap(storeIdIns);
			} catch (Exception e) {
				logger.error("获取门店信息异常",e);
				throw new BizException(500, "获取门店信息异常");
			}
		}

		//获取库存记录返回数据
		List<StockRecordBaseVo> recordVoList = getRecordVoList(dealerOutMap,dealerInMap,list);
				
		return recordVoList;
	}
	
	/**
	 *  获取库存记录返回数据
	 * @param dealerOutMap
	 * @param dealerInMap
	 * @param stockRecordBizDtoList
	 * @return
	 */
	private  List<StockRecordBaseVo>  getRecordVoList(Map<Integer, DealerStoreInfoBizDto> dealerOutMap,
			Map<Integer, DealerStoreInfoBizDto> dealerInMap,List<StockRecordBizDto> stockRecordBizDtoList){
       
		List<StockRecordBaseVo> stockRecordVoList=new ArrayList<>();
		
		for (StockRecordBizDto dto : stockRecordBizDtoList) {
			StockRecordBaseVo vo = Convert.toStockRecordBaseVo(dto);
			
			//获取发车方门店信息
			Integer outStockType = dto.getOutStockType();
			if(null != outStockType) {
				if(StockCarStockTypeEnum.STORE.getValue() == outStockType) {
					DealerStoreInfoBizDto  storeDtoOut = null == dealerOutMap ? null : dealerOutMap.get(dto.getOutStoreId());
					vo.setOutStockName(storeDtoOut == null ? null : storeDtoOut.getDealerShortName()+"-"+storeDtoOut.getStoreShortName());
				}
			}
			
			//获取收车方门店信息
			Integer inStockType = dto.getInStockType();
			if(null != inStockType) {
				if(StockCarStockTypeEnum.STORE.getValue() == dto.getInStockType()) {
					DealerStoreInfoBizDto  storeDtoIn = null == dealerInMap ? null : dealerInMap.get(dto.getInStoreId());
					vo.setInStockName(storeDtoIn == null ? null : storeDtoIn.getDealerShortName()+"-"+storeDtoIn.getStoreShortName());
				}
			}
			
			stockRecordVoList.add(vo);
		}
		return stockRecordVoList;
	}
	
	
	/**
	 * 根据门店或者中转库查 围栏数据信息
	 * @param map
	 * @return
	 */
	@Override
	public List<FenceBaseVo> getEntrepotOrStoreFence(Map<String, Object> map) {
		
		Integer fenceStoreStockType = ObjectCastUtil.castInteger(map.get("stockType"));
		FenceStoreStockTypeEnum  fenceStoreStockEnum= null;
		if(fenceStoreStockType == 2) {
			fenceStoreStockEnum = FenceStoreStockTypeEnum.STORE;
		}else {
			fenceStoreStockEnum = FenceStoreStockTypeEnum.ENTREPOT_STORAGE;
		}
		
		List<Integer> fenceId = fenceStoreStockService.getFenceByStoreId(ObjectCastUtil.castInteger(map.get("id")), fenceStoreStockEnum);
		if( null == fenceId || fenceId.isEmpty() ) {
			return null;
		}
		
		//查询围栏信息
		List<IovFenceDto> fenceList = iovFenceService.getFenceList(fenceId);
		return Convert.toFenceBaseVo(fenceList);
	}
	
	/**
	 * 验证围栏
	 * @param carDto
	 * @param stockCarDto
	 * @param exceptionStr
	 */
	private void getModifyBindingFenceVerify(CarDto carDto,StockCarDto stockCarDto,String exceptionStr) {
		Integer carId=carDto.getId();
		if(null == stockCarDto.getFenceId()) {
			 throw new BizException(101,"op车辆未绑定仓储下的围栏");
		}
		// 调取车联网接口 根据车辆VIN 获取围栏id
        List<String> vinList = new ArrayList<>(1);
        vinList.add(carDto.getVin());
        Map<String, List<IovFenceDto>> fenceMap = iovFenceService.getFenceByVins(vinList);

        //判断车联网接口返回围栏信息是否为空
        if(fenceMap == null || fenceMap.get(carDto.getVin()) == null || fenceMap.get(carDto.getVin()).size() <= 0){
            //新增异常 “车辆未绑定仓储下的围栏”
            FenceExceptionCreateDto fenceExceptionCreateDto = new FenceExceptionCreateDto();
            fenceExceptionCreateDto.setCarId(carId);
            fenceExceptionCreateDto.setFenceId(stockCarDto.getFenceId());
            fenceExceptionCreateDto.setStockId(carDto.getStockId());
            fenceExceptionCreateDto.setExplain(exceptionStr);
            carFenceExceptionService.createCarFenceException(fenceExceptionCreateDto);
            throw new BizException(101,exceptionStr);
        }
        Integer iovFenceId = fenceMap.get(carDto.getVin()).get(0).getId();
        // 判断围栏id是否一致
        if(!iovFenceId.equals(stockCarDto.getFenceId())){
            //新增异常 “车辆绑定仓储与车辆绑定围栏不符”
            FenceExceptionCreateDto fenceExceptionCreateDto = new FenceExceptionCreateDto();
            fenceExceptionCreateDto.setCarId(carId);
            fenceExceptionCreateDto.setFenceId(stockCarDto.getFenceId());
            fenceExceptionCreateDto.setStockId(carDto.getStockId());
            fenceExceptionCreateDto.setExplain("车辆绑定围栏与车联网不一致");
            carFenceExceptionService.createCarFenceException(fenceExceptionCreateDto);
            throw new BizException(101,"车辆绑定围栏与车联网不一致");
        }
	}

	/**
	 * 验证围栏
	 * @param carDto
	 * @param stockCarDto
	 * @param exceptionStr
	 */
	private void getBindingFenceVerify(CarDto carDto,StockCarDto stockCarDto,StockCarModifyVo modifyVo,String exceptionStr) {
		Integer carId=carDto.getId();
		// 调取车联网接口 根据车辆VIN 获取围栏id
        List<String> vinList = new ArrayList<>(1);
        vinList.add(carDto.getVin());
        Map<String, List<IovFenceDto>> fenceMap = iovFenceService.getFenceByVins(vinList);

        //判断车联网接口返回围栏信息是否为空
        if(fenceMap != null && fenceMap.get(carDto.getVin()) != null && fenceMap.get(carDto.getVin()).size() > 0){
            //新增车辆围栏异常 车辆已经绑定围栏
            FenceExceptionCreateDto fenceExceptionCreateDto = new FenceExceptionCreateDto();
            fenceExceptionCreateDto.setCarId(carId);
            fenceExceptionCreateDto.setFenceId(modifyVo.getFenceId());
            fenceExceptionCreateDto.setStockId(carDto.getStockId());
            fenceExceptionCreateDto.setExplain(exceptionStr);
            carFenceExceptionService.createCarFenceException(fenceExceptionCreateDto);
            throw new BizException(101,exceptionStr);
        }
        
	}
}
